package com.laterem.rtc.util;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @creator: alan wu
 * @dateTime: 2023/5/20 00:54
 * @desc:
 */
@Schema(title = "响应结果")
@Data
public class Result<T>{

    @Schema(title = "状态：200成功")
    private int code;
    @Schema(title = "提示信息")
    private String message;
    @Schema(title = "数据")
    private T data;

    public static Result ok(){
        Result<Object> result = new Result();
        result.setCode(200);
        result.setMessage("ok");
        result.setData(null);
        return result;
    }

    public static Result fail(){
        Result<Object> result = new Result();
        result.setCode(500);
        result.setMessage("fail");
        result.setData(null);
        return result;
    }

    public static Result fail(String message){
        Result<Object> result = new Result();
        result.setCode(500);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static Result fail(int code, String message){
        Result<Object> result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static <T>Result ok(T token) {
        Result<T> result = new Result();
        result.setCode(200);
        result.setMessage("ok");
        result.setData(token);
        return result;
    }
}
